package pattern.factory;

import pattern.factory.car.IPart;
import pattern.factory.car.impl.Navigation;
import pattern.factory.car.impl.SteeringWheel;
import pattern.factory.car.impl.Tire;

/**
 * 简单工厂模式
 * 避免创建者与具体的产品逻辑耦合、满足单一职责，每一个业务逻辑实现都在所属自己的类中完成、满足开闭原则，
 * 无需更改使用调用方就可以在程序中引入新的产品类型
 * @author ytj
 * @date 2025/8/6
 */
public class CarFactory {

    public IPart getPart(Integer type){
        switch (type){
            case 1:
                return new SteeringWheel();
            case 2:
                return new Navigation();
            case 3:
                return new Tire();
            default:
                return null;
        }
    }

    public static void main(String[] args) {
        CarFactory carFactory = new CarFactory();
        IPart part = carFactory.getPart(1);
        part.part();
        part = carFactory.getPart(2);
        part.part();
        part = carFactory.getPart(3);
        part.part();
    }
}
